<?php

namespace app\common\model;

use think\Model;

/**  YSF
 *   承包商合同
 *   Date: 2019/3/18
 * Class OaWorkersModel
 * @package app\common\model
 */
class OaWorkersContractModel extends Model {

	// 表名
	protected $name = 'oa_workers_contract';

	// 单表单条查询
	public function getOne($where = [], $field = '*') {
		$result = $this->where($where)
				->field($field)
				->find();
		return $result;
	}

	// 列表查询
	public function getAll($where, $join = [], $page = 1, $pageSize = -1, $field = '*', $order = 'c.workers_id desc') {
		if ($pageSize > 0) {
			$result = $this->alias('c')->where($where)
					->join($join)
					->field($field)
					->page($page, $pageSize)
					->order($order)
					->select();
		} else {
			$result = $this->alias('c')->where($where)
					->join($join)
					->field($field)
					->order($order)
					->select();
		}
		return $result;
	}
	//新增
	public function add($data = []) {
		$result = $this->insertGetId($data);
		return $result;
	}

	// 编辑操作
	public function edit($where = [], $data = []) {
		$result = $this->where($where)->update($data);
		return $result;
	}

	// 数量查询
	public function getCount($where=[], $join = []) {
		$result = $this->alias('c')->where($where)
				->join($join)
				->count();
		return $result;
	}
	// 分组查询
	public function getGroupAll($where, $join = [],$field='*',$group='') {
		$result = $this->alias('c')->where($where)
					->join($join)
					->group($group)
					->field($field)
					->select();
		return $result;
	}

}
